package com.bindapp.activity;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.bindapp.R;
import com.bindapp.bean.LoginBean;
import com.bindapp.bean.SmsBean;
import com.bindapp.bean.TextBean;
import com.bindapp.databinding.ActivityTextBinding;
import com.bindapp.http.MNetSocketHttp;
import com.bindapp.http.QueueRequest;
import com.bindapp.listener.HttpListener;
import com.bindapp.util.DeviceSearcher;
import com.bindapp.util.Static;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Created by apple on 2018/6/28.
 */

public class TextActivity extends AppCompatActivity {
    private ActivityTextBinding binding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding=DataBindingUtil.setContentView(this, R.layout.activity_text);
        binding.submit.setOnClickListener(new ViewClick());

        binding.seekbar.setSelected(true);
        binding.seekbar.setSelectedMinValue(30);
        binding.seekbar.setSelectedMaxValue(100);

    }

    class ViewClick implements View.OnClickListener{

        @Override
        public void onClick(View view) {
            //request4();

            //import com.esotericsoftware.kryo.Kryo
            //request1();
            //request2();
            //reques≥t4();


            //request5();
            request6();

            //searchDevices_broadcast();
        }
    }

    private void request1(){
        Map<String,Object> params=new HashMap<String,Object>();
        params.put("op","login");
        params.put("password","1");
        params.put("userId","test");
        MNetSocketHttp.getInstance().getNormalRequest(params,LoginBean.class, new HttpListener() {
            @Override
            public void success(Object obj) {

                if(((LoginBean)obj).getSuccess()){
                    Static.myLog("成功LoginBean->"+((LoginBean)obj).getMessage());
                }else{
                    Static.myLog("失败");

                }
            }

            @Override
            public void fail(String msg) {
                Static.myLog(msg);
            }
        });
    }
    private void request2(){
        Map<String,Object> params2=new HashMap<String,Object>();
        params2.put("op","requestVCode");
        params2.put("phone","18868945495");
        MNetSocketHttp.getInstance().getNormalRequest(params2,SmsBean.class, new HttpListener() {
            @Override
            public void success(Object obj) {
                Static.myLog("成功SmsBean->"+((SmsBean)obj).getMessage());
            }

            @Override
            public void fail(String msg) {
                Static.myLog(msg+"SmsBean");
            }
        });
    }

    private void request3(){
        Map<String,Object> params3=new HashMap<String,Object>();
        params3.put("op","1");
        MNetSocketHttp.getInstance().getNormalRequest(params3,TextBean.class, new HttpListener() {
            @Override
            public void success(Object obj) {
                Static.myLog("成功TextBean");
            }

            @Override
            public void fail(String msg) {
                Static.myLog(msg+"TextBean");
            }
        });
    }

    public void request5(){
        Map<String,Object> params2=new HashMap<String,Object>();
        params2.put("op","requestVCode");
        params2.put("phone","18868945495");
        QueueRequest.getInstance().addListRequest(params2,SmsBean.class,new HttpListener() {
            @Override
            public void success(Object obj) {
                Static.myLog("成功SmsBean->"+((SmsBean)obj).getMessage());
            }

            @Override
            public void fail(String msg) {
                Static.myLog(msg+"SmsBean");
            }
        });
    }


    public void request6(){
        Map<String,Object> params=new HashMap<String,Object>();
        /*params.put("op","login");
        params.put("password","1");
        params.put("userId","test");*/
        QueueRequest.getInstance().addListRequest(params,LoginBean.class, new HttpListener() {
            @Override
            public void success(Object obj) {

                if(((LoginBean)obj).getSuccess()){
                    Static.myLog("成功LoginBean->"+((LoginBean)obj).getMessage());
                }else{
                    Static.myLog("失败");

                }
            }

            @Override
            public void fail(String msg) {
                Static.myLog(msg);
            }
        });
    }

    private void searchDevices_broadcast() {
        new DeviceSearcher() {
            @Override
            public void onSearchStart() {
                //startSearch();
            }

            @Override
            public void onSearchFinish(Set deviceSet) {
                Log.e("Mytext",""+deviceSet.size());
            }
        }.start();
    }

    public class SomeRequest {
        public String text;
    }
    public class SomeResponse {
        public String text;
    }
}
